import bobo
import os

os.chdir("/Users/wxh/py-plays/")


def meta(tag):
    print("type", type(tag))
    print("__name__", tag.__name__)
    print(
        f"\n    --- ".join(["函数元信息"] + [x for x in dir(tag) if not x.startswith("__")]),
        "\n元信息结束",
    )
    print("func_code", tag.func_code)
    print(
        "\n    --- ".join(
            ["codes 展开"] + [x for x in dir(tag.func_code) if not x.startswith("__")]
        ),
        "\ncodes 结束",
    )
    print(
        "__qualname__", tag.__qualname__ if hasattr(tag, "__qualname__") else "no exits"
    )
    print(
        "__globals__",
        [x for x in tag.__globals__ if not x.startswith("__")]
        if hasattr(tag, "__globals__")
        else "不能访问",
    )
    print("__defaults__", tag.__defaults__ if hasattr(tag, "__defaults__") else "不能访问")
    print(
        "__kwdefaults__",
        tag.__kwdefaults__ if hasattr(tag, "__kwdefaults__") else "不能访问",
    )
    print(
        "__annotations__",
        tag.__annotations__ if hasattr(tag, "__annotations__") else "不能访问",
    )
    print("__closure__", tag.__closure__ if hasattr(tag, "__closure__") else "不能访问")


@bobo.query("/")
def person(name="fuck-defaults"):
    return "Hello," + name


def test():
    """
    >>> meta(person) # doctest: +ELLIPSIS
        type <class 'bobo._Handler'>
    __name__ person
    函数元信息
        --- bobo_handle
        --- bobo_methods
        --- bobo_order
        --- bobo_original
        --- bobo_reroute
        --- bobo_response
        --- bobo_route
        --- bobo_sub_find
        --- check
        --- content_type
        --- func_code
        --- func_defaults
        --- handler
        --- match
        --- params
        --- partial
    元信息结束
    func_code <code object person at 0x.., file "/Users/wxh/py-plays/hello-bobo-framwork.py", line 42>
    codes 展开
        --- co_argcount
        --- co_cellvars
        --- co_code
        --- co_consts
        --- co_filename
        --- co_firstlineno
        --- co_flags
        --- co_freevars
        --- co_kwonlyargcount
        --- co_lnotab
        --- co_name
        --- co_names
        --- co_nlocals
        --- co_posonlyargcount
        --- co_stacksize
        --- co_varnames
        --- replace
    codes 结束
    __qualname__ no exits
    __globals__ 不能访问
    __defaults__ 不能访问
    __kwdefaults__ 不能访问
    __annotations__ 不能访问
    __closure__ 不能访问
    """


if __name__ == "__main__":
    import doctest

    print("hello-bobo-framwork 测试开始")
    (ff, tt) = doctest.testmod()
    print("测试结束:统计-失败{},总计{}".format(ff, tt))
    print("√" * tt if tt > 0 and not ff else "无测试" if not ff else "×" * ff)
